home *** CD-ROM | disk | FTP | other *** search
/ Aminet 52 / Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso / Aminet / util / libs / ttengine.lha / ttengine-4.1 / Examples / FontNames / names.c < prev    next >
C/C++ Source or Header  |  2002-09-29  |  6KB  |  152 lines

  1. /* test ttrender */
  2.  
  3. #define __NOLIBBASE__
  4.  
  5. #include <proto/dos.h>
  6. #include <proto/exec.h>
  7. #include <proto/intuition.h>
  8. #include <proto/graphics.h>
  9. #include <proto/ttengine.h>
  10. #include <proto/asl.h>
  11.  
  12. #include <libraries/ttengine.h>
  13.  
  14. extern struct Library *SysBase, *DOSBase;
  15.  
  16. /*----------------------------------------------------------------------------------------------------*/
  17.  
  18. static STRPTR get_font_name(struct Library *AslBase)
  19.   {
  20.     struct FileRequester *freq;
  21.     STRPTR name = NULL;
  22.  
  23.     if (freq = AllocAslRequestTags(ASL_FileRequest, TAG_END))
  24.       {
  25.         if (AslRequestTags(freq,
  26.           ASLFR_TitleText, (ULONG)"Select TrueType font",
  27.           ASLFR_InitialDrawer, (ULONG)"FONTS:",
  28.           ASLFR_DoPatterns, TRUE,
  29.           ASLFR_InitialPattern, (ULONG)"#?.ttf",
  30.           ASLFR_RejectIcons, TRUE,
  31.           TAG_END))
  32.           {
  33.             ULONG namelen = strlen(freq->fr_File) + strlen(freq->fr_Drawer) + 4;
  34.  
  35.             if (name = AllocVec(namelen + 1, MEMF_ANY | MEMF_CLEAR))
  36.               {
  37.                 strncpy(name, freq->fr_Drawer, namelen);
  38.                 AddPart(name, freq->fr_File, namelen);
  39.               }
  40.           }
  41.         FreeAslRequest(freq);
  42.       }
  43.     return name;
  44.   }
  45.  
  46. /*----------------------------------------------------------------------------------------------------*/
  47.  
  48. static VOID free_font_name(STRPTR name)
  49.   {
  50.     if (name) FreeVec(name);
  51.   }
  52.  
  53. /*----------------------------------------------------------------------------------------------------*/
  54.  
  55. int Main (void)
  56.   {
  57.     struct Library *TTEngineBase, *IntuitionBase, *GfxBase, *AslBase;
  58.     struct Window *win;
  59.     STRPTR fontname;
  60.     APTR font;
  61.  
  62.     if (GfxBase = OpenLibrary("graphics.library", 39))
  63.       {
  64.         if (IntuitionBase = OpenLibrary("intuition.library", 39))
  65.           {
  66.             if (AslBase = OpenLibrary("asl.library", 38))
  67.               {
  68.                 if (fontname = get_font_name(AslBase))
  69.                   {
  70.                     if (TTEngineBase = OpenLibrary("ttengine.library", 4))
  71.                       {
  72.                         if (win = OpenWindowTags(NULL,
  73.                           WA_Top, 25,
  74.                           WA_Left, 0,
  75.                           WA_Width, 400,
  76.                           WA_Height, 100,
  77.                           WA_CloseGadget, TRUE,
  78.                           WA_DragBar, TRUE,
  79.                           WA_DepthGadget, TRUE,
  80.                           WA_IDCMP, IDCMP_CLOSEWINDOW,
  81.                           WA_Title, (ULONG)"TTEngine font names",
  82.                           TAG_END))
  83.                           {
  84.                             ULONG sigmask, signals;
  85.                             BOOL running = TRUE;
  86.                             struct RastPort *rp = win->RPort;
  87.  
  88.                             if (font = TT_OpenFont(
  89.                               TT_FontFile, (ULONG)fontname,
  90.                               TT_FontSize, 18,
  91.                             TAG_END))
  92.                               {
  93.                                 STRPTR family, subfamily, fullname;
  94.  
  95.                                 TT_SetFont(rp, font);
  96.                                 TT_SetAttrs(rp,
  97.                                   TT_Window, (ULONG)win,
  98.                                   TT_Encoding, TT_Encoding_Default,
  99.                                   TT_Antialias, TT_Antialias_On,
  100.                                 TAG_END);
  101.  
  102.                                 TT_GetAttrs(rp,
  103.                                   TT_FamilyName, (ULONG)&family,
  104.                                   TT_SubfamilyName, (ULONG)&subfamily,
  105.                                   TT_FontName, (ULONG)&fullname,
  106.                                 TAG_END);
  107.  
  108.                                 SetAPen(rp, 1);
  109.                                 SetDrMd(rp, JAM1);
  110.  
  111.                                 Move(rp, 10, 36);
  112.                                 TT_Text(rp, family, strlen(family));
  113.                                 Move(rp, 10, 54);
  114.                                 TT_Text(rp, subfamily, strlen(subfamily));
  115.                                 Move(rp, 10, 72);
  116.                                 TT_Text(rp, fullname, strlen(fullname));
  117.  
  118.                                 TT_CloseFont(font);
  119.                               }
  120.                             else PutStr("Font open failed.\n");
  121.  
  122.                             sigmask = SIGBREAKF_CTRL_C | (1 << win->UserPort->mp_SigBit);
  123.                             while (running)
  124.                               {
  125.                                 signals = Wait(sigmask);
  126.                                 if (signals & SIGBREAKF_CTRL_C) running = FALSE;
  127.                                 if (signals & (1 << win->UserPort->mp_SigBit))
  128.                                   {
  129.                                     struct IntuiMessage *imsg;
  130.  
  131.                                     while (imsg = (struct IntuiMessage*)GetMsg(win->UserPort))
  132.                                       {
  133.                                         if (imsg->Class == IDCMP_CLOSEWINDOW) running = FALSE;
  134.                                         ReplyMsg((struct Message*)imsg);
  135.                                       }
  136.                                   }
  137.                               }
  138.                             CloseWindow(win);
  139.                           }
  140.                         CloseLibrary(TTEngineBase);
  141.                       }
  142.                     free_font_name(fontname);
  143.                   }
  144.                 CloseLibrary(AslBase);
  145.               }
  146.             CloseLibrary(IntuitionBase);
  147.           }
  148.         CloseLibrary(GfxBase);
  149.       }
  150.     return 0;
  151.   }
  152.